package com.rs.game.player.dialogues.impl;

import java.util.Random;

import com.rs.Settings;
import com.rs.game.World;
import com.rs.game.item.Item;
import com.rs.game.player.dialogues.Dialogue;
import com.rs.utils.Utils;

public class DicingMaster extends Dialogue{

	private int npcId;

	@Override
	public void start() {
		npcId = (Integer) parameters[0];
		sendNPCDialogue(npcId, 9827, "Hello, you can bet 5M to win the Gamble Item of the Week. You need to roll over 90 in order to win. The current Gamble Item of the Week is:<col=ff0000> "+Settings.GAMBLE_ITEM_OF_THE_WEEK+".</col>" +
				"So, would you like to play?");
	}

	@Override
	public void run(int interfaceId, int componentId) {
		if (stage == -1) {
			stage = 0;
			sendOptionsDialogue("Select an Option", "Yes", "No");
		} else if (stage == 0) {
			if (componentId == OPTION_1) {
				Random rand = new Random();
				int roll = rand.nextInt(100) + 1;
				if (player.getInventory().getCoinsAmount() >= 5000000) {
					player.getInventory().removeItemMoneyPouch(new Item (995, 5000000));
					if (roll >= 90) {
						sendNPCDialogue(npcId, 9827, "You have rolled <col=db3535>"+("" + roll)+"");
						player.getInventory().addItem(Settings.GIOTW, 1);
						World.sendWorldMessage("<col=09963B> " + Utils.formatPlayerNameForDisplay(player.getDisplayName()) + " has just received the " + "<col=2098E3>" +Settings.GAMBLE_ITEM_OF_THE_WEEK+ "</col>" + "<col=09963B>" + " from the Gambler by rolling: "+roll+"!", false);
						stage = 1;
					} else {
						sendNPCDialogue(npcId, 9827, "You have rolled <col=db3535>"+("" + roll)+"");
						stage = 1;
					}
				} else {
					player.getPackets().sendGameMessage("You need 5M in order to participate.");
					end();
				}
			} else if (componentId == OPTION_2) {
				end();
			}
		} else if (stage == 1) {
			end();
		}
	}

	@Override
	public void finish() {
		// TODO Auto-generated method stub
		
	}
}